package com.example.modual.controller;

import com.example.common.resp.RespJsonData;
import com.example.modual.service.UploadService;
import com.example.oss.annotation.ValidFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;

/**
 * <h1>文件上传控制层</h1>
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020/6/24
 */
@Validated
@RestController
@RequestMapping(value = "/upload")
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * <h2>图片上传</h2>
     * @param files             上传的文件
     * @param uploadType        上传的类型
     * @param request           http请求对象
     * @param response          http返回对象
     * @return
     * @throws IOException
     */
    @PostMapping(value = "/uploadImage")
    public RespJsonData uploadImage(@Valid @ValidFile(maxSize = "10MB",value = {".jpg",".jpeg",".png",".JPG",".JPEG",".PNG"})MultipartFile[] files, String uploadType, HttpServletRequest request, HttpServletResponse response) throws IOException {
        return uploadService.uploadImage(files,uploadType,request,response);
    }
}
